package com.example.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.demo.data.model.Users;
import com.example.demo.databinding.ActivityRegisterBinding;

public class RegisterActivity extends AppCompatActivity {

    private ActivityRegisterBinding binding;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityRegisterBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        bindLogin();
    }

    private void bindLogin() {
        binding.loginBtn.setOnClickListener(v -> {
            String name = binding.username.getText().toString();
            String pwd = binding.password.getText().toString();
            String pwdAgain = binding.passwordAgain.getText().toString();
            if(!pwd.equals(pwdAgain)){
                Toast.makeText(getApplicationContext(), "两次输入的密码不一致",Toast.LENGTH_SHORT).show();
            } else {
                if(Users.users.get(name)!=null){
                    Toast.makeText(getApplicationContext(), "用户已注册",Toast.LENGTH_SHORT).show();
                } else {
                    Users.users.put(name, pwd);
                    startActivity(new Intent());
                }
            }
        });
    }
}